package com.demo.chapter12date;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

//格式化输出
public class DateTimeFormatterDemo {
	
	public static void demo(){
		LocalDate date = LocalDate.of(2016, 9, 18);
		System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));//20160918
		System.out.println(date.format(DateTimeFormatter.ISO_LOCAL_DATE));//2016-09-18
		
		LocalDate date2 = LocalDate.parse("20161018", DateTimeFormatter.BASIC_ISO_DATE);
		LocalDate date3 = LocalDate.parse("2016-09-18", DateTimeFormatter.ISO_LOCAL_DATE);
	}
	
	public static void demo2(){
		//按特定格式创建格式器
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
		LocalDate date = LocalDate.of(2016, 9, 18);//18/09/2016
		System.out.println(date.format(formatter));
		
		LocalDate date2 = LocalDate.parse("18/09/2016", formatter);
	}
	
	public static void main(String[] args) {
		demo();
		demo2();
	}

}
